/**
 *
 */
package com.nest.WorkNest.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nest.WorkNest.R;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 类名称：RecordAdapter 类描述： 创建人：何琳 创建时间：2015年7月28日 下午2:28:15
 */
public class StatusAdapter extends BaseAdapter {

    private ArrayList<HashMap<String, String>> dataList;
    private Context context;

    public StatusAdapter(Context context, ArrayList<HashMap<String, String>> dataList) {
        this.dataList = dataList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    private class ViewHolder {
        TextView operation;
        TextView time;
        TextView content;
        ImageView node;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_status_record_item,
                    null);
            holder.operation = (TextView) convertView.findViewById(R.id.operation);
            holder.time = (TextView) convertView.findViewById(R.id.time);
            holder.node = (ImageView) convertView.findViewById(R.id.subsection_point);
            holder.content = (TextView) convertView.findViewById(R.id.content);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        HashMap<String, String> map = dataList.get(position);
        String state = map.get("state");
        holder.operation.setText(map.get("executor"));
        holder.time.setText(map.get("time"));
        holder.time.setText(map.get("content"));
        if ("check".equals(state)) {
            holder.operation
                    .setTextColor(context.getResources().getColor(R.color.mainfontcolor_orange));
            holder.node.setBackgroundResource(R.drawable.node_pressed);
        } else if ("uncheck".equals(state)) {
            holder.operation
                    .setTextColor(context.getResources().getColor(R.color.gray_8B));
            holder.node.setBackgroundResource(R.drawable.node_nomal);
        }
        return convertView;
    }

    public void update(ArrayList<HashMap<String, String>> datalist) {
        this.dataList = datalist;
        notifyDataSetChanged();
    }
}
